package com.js.sys.greendao.db;


import com.google.gson.Gson;
import com.js.lib_common.mvp.model.response.BindBean;
import com.js.sys.BaseApplication;
import com.js.sys.greendao.DBHelper;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

@Entity
public class BindingHistory {

    @Id(autoincrement = true)
    public Long id;

    /**
     * 是否已上传
     */
    public Boolean isUpload;


    /**
     * 操作人员
     */
    private String name;

    /**
     * 录入时间
     */
    private String time;

    /**
     * 录入的JSON数据
     */
    private String json;

    /**
     * 录入的数据的类型，1绑定、2检查、3入库、4出库
     */
    private int type;
    private String des;
    @Generated(hash = 1218572846)
    public BindingHistory(Long id, Boolean isUpload, String name, String time, String json,
            int type, String des) {
        this.id = id;
        this.isUpload = isUpload;
        this.name = name;
        this.time = time;
        this.json = json;
        this.type = type;
        this.des = des;
    }

    @Generated(hash = 1475573239)
    public BindingHistory() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Boolean getIsUpload() {
        return this.isUpload;
    }

    public void setIsUpload(Boolean isUpload) {
        this.isUpload = isUpload;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTime() {
        return this.time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getJson() {
        return this.json;
    }

    public void setJson(String json) {
        this.json = json;
    }

    public int getType() {
        return this.type;
    }

    public void setType(int type) {
        this.type = type;
    }


    @Override
    public String toString() {
        return "BindingHistory{" +
                "id=" + id +
                ", isUpload=" + isUpload +
                ", name='" + name + '\'' +
                ", time='" + time + '\'' +
                ", json='" + json + '\'' +
                ", type=" + type +
                ", des='" + des + '\'' +
                '}';
    }

    public String getDes() {
        return this.des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    public static void insertHistory(BindBean mBindBean, boolean isUpload, int type, String des) {
        if (mBindBean ==null) {
            return;
        }
        BindingHistory bean = new BindingHistory();
        List<BindBean> list=new ArrayList<>();
        list.add(mBindBean);
        bean.setJson(new Gson().toJson(list));
        String date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.CHINA)
                .format(new java.util.Date());
        bean.setTime(date);
        bean.setIsUpload(isUpload);
        bean.setType(type);
        bean.setDes(des);
        bean.setName(BaseApplication.userName);
        DBHelper.getInstance().getSession().getBindingHistoryDao().insert(bean);
    }

    public static void insertHistory(List<BindBean>list, boolean isUpload, int type, String des) {
        if (list==null) {
            return;
        }
        BindingHistory bean = new BindingHistory();
        bean.setJson(new Gson().toJson(list));
        String date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.CHINA)
                .format(new java.util.Date());
        bean.setTime(date);
        bean.setIsUpload(isUpload);
        bean.setType(type);
        bean.setDes(des);
        bean.setName(BaseApplication.userName);
        DBHelper.getInstance().getSession().getBindingHistoryDao().insert(bean);
    }

}